/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: SelfEvaluation.java
 * Date: 16/11/2010
 */

package com.ingenius.sau.shared.model.core;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.FetchGroup;
import javax.jdo.annotations.FetchGroups;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NullValue;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.ingenius.sau.shared.model.programs.AcademicProgram;

/**
 * Class <strong>SelfEvaluation</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@FetchGroups({
		@FetchGroup(name = "with_program", members = { @Persistent(name = "academicProgram") }),
		@FetchGroup(name = "with_factors", members = { @Persistent(name = "factors2Evaluate") }) })
public class SelfEvaluation implements BaseBean {

	// CONSTANTS

	public static final String ACTIVE = "Active";

	public static final String INACTIVE = "Inactive";

	// DATA

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;

	@Persistent(nullValue = NullValue.NONE)
	private String name;

	@Persistent(nullValue = NullValue.NONE)
	private String description;

	@Persistent(nullValue = NullValue.NONE)
	private String state = ACTIVE;

	@Persistent(nullValue = NullValue.NONE)
	private Date startDate;

	@Persistent(nullValue = NullValue.NONE)
	private Date deliveryDate;

	@Persistent
	private AcademicProgram academicProgram;

	@Persistent
	private String guidelineId;

	@Persistent
	private String scaleId;

	@Persistent
	private float grade;

	@Persistent(mappedBy = "process")
	@Element(dependent = "true")
	private List<Factor2Evaluate> factors2Evaluate;

	// CONSTRUCTORS

	public SelfEvaluation() {
	}

	public SelfEvaluation(String id) {
		this.id = id;
	}

	// METHODS

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		if (ACTIVE.equals(state) || INACTIVE.equals(state)) {
			this.state = state;

		} else {
			System.out.println("Invalid argument exception. " + state);
		}

	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getDeliveryDate() {
		return deliveryDate;
	}

	public void setDeliveryDate(Date deliveryDate) {
		this.deliveryDate = deliveryDate;
	}

	public AcademicProgram getAcademicProgram() {
		return academicProgram;
	}

	public void setAcademicProgram(AcademicProgram academicProgram) {
		this.academicProgram = academicProgram;
	}

	public String getGuidelineId() {
		return guidelineId;
	}

	public void setGuidelineId(String guidelineId) {
		this.guidelineId = guidelineId;
	}

	public String getScaleId() {
		return scaleId;
	}

	public void setScaleId(String scaleId) {
		this.scaleId = scaleId;
	}

	public float getGrade() {
		return grade;
	}

	public void setGrade(float grade) {
		this.grade = grade;
	}

	public List<Factor2Evaluate> getFactors2Evaluate() {
		return (factors2Evaluate == null) ? factors2Evaluate = new ArrayList<Factor2Evaluate>()
				: factors2Evaluate;
	}

	public void setFactors2Evaluate(List<Factor2Evaluate> factors2Evaluate) {
		this.factors2Evaluate = factors2Evaluate;
	}

	public void addFactor2Evaluate(Factor2Evaluate factor2Evaluate) {
		getFactors2Evaluate().add(factor2Evaluate);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof SelfEvaluation) {
			return ((SelfEvaluation) obj).getId().equals(id);
		}
		return false;
	}

	@Override
	public SelfEvaluation toDTO() {
		if (this != null) {
			this.setFactors2Evaluate(null);
		}
		return this;
	}

}
